Refs

Draft version, still lots to explore

library(maptools)
## Warning: package 'maptools' was built under R version 3.1.1
## Loading required package: sp
## Warning: package 'sp' was built under R version 3.1.1
## Checking rgeos availability: FALSE
##      Note: when rgeos is not available, polygon geometry     computations in maptools depend on gpclib,
##      which has a restricted licence. It is disabled by default;
##      to enable gpclib, type gpclibPermit()
uk <- readShapeSpatial("map.shp", proj4string=CRS("+proj=longlat"))
plot(uk)

plot of chunk unnamed-chunk-1

summary(uk)
## Object of class SpatialPolygonsDataFrame
## Coordinates:
##      min    max
## x -13.69  1.764
## y  49.87 60.846
## Is projected: FALSE 
## proj4string : [+proj=longlat]
## Data attributes:
##      MM_UID           CODE                  NAME1               NAME2    
##  Min.   :  1.0   GB.ED  :  2   England         :112   Aberdeen     :  1  
##  1st Qu.: 48.8   GB.AB  :  1   Northern Ireland: 26   Aberdeenshire:  1  
##  Median : 96.5   GB.AD  :  1   Scotland        : 32   Anglesey     :  1  
##  Mean   : 96.5   GB.AG  :  1   Wales           : 22   Angus        :  1  
##  3rd Qu.:144.2   GB.AM  :  1                          Antrim       :  1  
##  Max.   :192.0   GB.AN  :  1                          Ards         :  1  
##                  (Other):185                          (Other)      :186  
##          DIVISION  
##  Kingdom     :144  
##  Principality: 22  
##  Province    : 26  
##                    
##                    
##                    
## 
library(maps)
## Warning: package 'maps' was built under R version 3.1.1
france<-map(database="france")

plot of chunk unnamed-chunk-2

names(france)
## [1] "x"     "y"     "range" "names"
head(france$names)
## [1] "Nord"           "Pas-de-Calais"  "Somme"          "Nord:1"        
## [5] "Ardennes"       "Seine-Maritime"
library(mapdata)
## Warning: package 'mapdata' was built under R version 3.1.1
map(database="worldHires", "Portugal") 

plot of chunk unnamed-chunk-3

library(RgoogleMaps)
## Warning: package 'RgoogleMaps' was built under R version 3.1.1
lat <- c(37,42) #define our map's ylim
lon <- c(-9,-6) #define our map's xlim
center = c(mean(lat), mean(lon))  #tell what point to center on
zoom <- 7  #zoom: 1 = furthest out (entire globe), larger numbers = closer in

terrmap <- GetMap(center=center, zoom=zoom, maptype= "terrain", destfile = "terrain.png") 
# lots of visual options, just like google maps: 
#   maptype = c("roadmap", "mobile", "satellite", "terrain", "hybrid", "mapmaker-roadmap", "mapmaker-hybrid")
PlotOnStaticMap(terrmap)

plot of chunk unnamed-chunk-4

path = paste0("&path=color:0x0000ff|weight:3|",
              "38.7138,-9.14|39.12,-9.21|39.0,-8.5")
MyMap <- GetMap(center=center, zoom=zoom, path = path)
PlotOnStaticMap(MyMap)

plot of chunk unnamed-chunk-4

library(ggmap)
## Warning: package 'ggmap' was built under R version 3.1.1
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.1.1
library(geosphere) # use: gcIntermediate
## Warning: package 'geosphere' was built under R version 3.1.1
# this example shows obtaining coordinates (latitude, longitude) using
# map_world function, and drawing them using geom_polygon
world <- map_data("world")
basemap <- ggplot(legend = FALSE) + 
           geom_polygon(data = world, aes(x = long,  y = lat, group = group, fill = group)) + 
           theme(legend.position = "none")  

lx <- geocode("Lisbon, PT") # find coordinates
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Lisbon,+PT&sensor=false
## Google Maps API Terms of Service : http://developers.google.com/maps/terms
ny <- geocode("New York, USA")
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=New+York,+USA&sensor=false
## Google Maps API Terms of Service : http://developers.google.com/maps/terms
inter <- as.data.frame(gcIntermediate(c(lx$lon, lx$lat), c(ny$lon, ny$lat), n = 50, addStartEnd = TRUE))
basemap + geom_line(data = inter, aes(x = lon, y = lat), color = "red")

plot of chunk unnamed-chunk-5

# using maps to plot routes
rt1 = route(from = "Lisbon", to = "Castelo Branco", mode = "driving")
## Information from URL : http://maps.googleapis.com/maps/api/directions/json?origin=Lisbon&destination=Castelo+Branco&mode=driving&units=metric&alternatives=false&sensor=false
## Google Maps API Terms of Service : http://developers.google.com/maps/terms
PortugalMap <- qmap("Portugal", zoom = 8, color = "bw")
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=Portugal&zoom=8&size=%20640x640&scale=%202&maptype=terrain&sensor=false
## Google Maps API Terms of Service : http://developers.google.com/maps/terms
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Portugal&sensor=false
## Google Maps API Terms of Service : http://developers.google.com/maps/terms
PortugalMap + geom_leg(aes(x = startLon, y = startLat, xend = endLon, yend = endLat),
                       color = "blue", data = rt1)

plot of chunk unnamed-chunk-6

# select a map and plot some markers
LisbonMap = qmap("Lisboa", zoom = 16, color = "bw", maptype='hybrid', legend = "topleft",
                 location = c(lon = -9.138, lat = 38.7098))
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=38.7098,-9.138&zoom=16&size=%20640x640&scale=%202&maptype=hybrid&sensor=false
## Google Maps API Terms of Service : http://developers.google.com/maps/terms
LisbonMap

plot of chunk unnamed-chunk-6

# make some data
df <- data.frame(lat=c(38.7098,38.7139,38.7122),
                 lon=c(-9.1330,-9.1336,-9.1400),
                 type=c("igreja", "castelo", "igreja"),
                 nome=c("sé lisboa", "castelo são jorge", "convento do carmo" ))
df
##     lat    lon    type              nome
## 1 38.71 -9.133  igreja         sé lisboa
## 2 38.71 -9.134 castelo castelo são jorge
## 3 38.71 -9.140  igreja convento do carmo
LisbonMap + geom_point(aes(x = lon, y = lat, colour = type, shape=type), data = df)

plot of chunk unnamed-chunk-6

library(maps)
library(mapproj)

countries <- c("Portugal", "Poland", "Greece", "Iran", "Brazil")

m <- map("world", plot = FALSE)
countryMatch <- match.map("world", countries)

# color code any states with visit data as light blue
colorCountry <- sapply(countryMatch, function(c) {
    if (!is.na(c)) 
        c <- "#FF0000" else c <- "#FFFFFF"
})

map("world", proj = "azequalarea", orient = c(25, 10, 0), boundary = TRUE, col = colorCountry, fill = TRUE)
map.grid(m, col = "lightblue", label = FALSE, lty = 2, pretty = TRUE)
map.scale()

plot of chunk unnamed-chunk-7